﻿using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{

    public partial class TGASTGA : ViewBase
    {
        #region ==CART===========
        public static readonly DependencyProperty CARTProperty = DependencyProperty.Register("CART",
            typeof(string), typeof(TGASTGA),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCARTChanged));
        public string CART
        {
            get
            {
                return (string)GetValue(CARTProperty);
            }
            set
            {
                SetValue(CARTProperty, value);
                LOAD();
            }
        }
        private static void OnCARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TGASTGA;
            if (src != null)
            {
                src.CART = (string)e.NewValue;
            }
        }
        #endregion
        #region ==BOM===========
        public static readonly DependencyProperty BOMProperty = DependencyProperty.Register("BOM",
            typeof(DataTable), typeof(TGASTGA),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnBOMChanged));
        public DataTable BOM
        {
            get
            {
                return MV.TBMain;
            }
            set
            {
                SetValue(BOMProperty, value);
                MV.TBMain = value;
             }
        }
        private static void OnBOMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TGASTGA;
            if (src != null)
            {
                src.BOM = (DataTable)e.NewValue;
            }
        }
        #endregion 

        #region ==dwBOM===========
        public static readonly DependencyProperty dwBOMProperty = DependencyProperty.Register("dwBOM",
            typeof(DataRow), typeof(TGASTGA),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwBOMChanged));
        public DataRow dwBOM
        {
            get
            {
                return (DataRow)GetValue(dwBOMProperty);
            }
            set
            {
                SetValue(dwBOMProperty, value);
            }
        }
        private static void OndwBOMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TGASTGA;
            if (src != null)
            {
                src.dwBOM = (DataRow)e.NewValue;
            }
        }
        #endregion
        public TGASTGA()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VGASTGA();
            DataContext = MV;
            InitializeComponent();
        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded) return;
            base.Window_Loaded(sender, e);
        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwBOM = dwMaster; 
        }
        public void LOAD()
        {
            PM["CART"] = CART;
            ((VGASTGA)MV).LOAD(PM);
        }
      
    }
}
